<?php require_once('menu.php'); ?>
<script language="javascript">
<!--
 var msg = '<?=$alert?>'
 if (msg) {
    alert(msg)
 }
 -->
</script>
<script type="text/javascript">
$().ready(function() {
    $("#businessForm").validate({
        errorLabelContainer: $("#businessForm div.error")
    });
});
</script>
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="menudottedline" width="40%">
            <div class="pathway"></div>
        </td>
        <td class="menudottedline" align="right">
            <table cellpadding="0" cellspacing="0" border="0" id="toolbar">
                <tr height="60" valign="middle" align="center">
                    <td>
                        <a class="toolbar" href="#">
                        <?php echo $html->image('admin/help_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Help
                        </a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<br>
<br>
<div align="center" class="centermain">
    <div class="main">
        <table class="adminheading">
            <tr>
                <th class="info" rowspan="2" nowrap>Business Profile</th>
            </tr>
        </table>

        <table class="adminform">
            <tr>
                <td width="60%" valign="top">
                    <form name="adminForm" method="post" action="<?=$html->url('/admin/bprofile')?>" enctype="multipart/form-data">
                    <table class="adminlist" cellpadding=20>
                        <tr>
                            <th colspan=4>Business List</th>
                        </tr>
						<tr>
							<td width="5%" class="subheader">#</td>
							<td align="left" width="30%" class="subheader">Name</td>
							<td align="left" width="20%" class="subheader">Plan</td>
							<td width="%" class="subheader" align="center">Active</td>
						</tr>
					<?php
					 if ($blist) {
					 	foreach ($blist as $idx => $b) {
                        	$color = ($idx/2 == round($idx/2)) ? "row0" : "row1";
                     ?>
						<tr class="<?=$color?>">
							<td><?=$idx+1?></td>
							<td align="left"><?=$html->link($b['businesses']['name'], '/admin/bprofile/'.$b['businesses']['id'])?></td>
							<td align="left"><?=$b['plans']['package']?></td>
							<td align="center"><?=($b['businesses']['active']==1) ? "Yes" : "No"?></td>
						</tr>
                    <?php
					 	}
					 }
					 ?>
						<tr bgcolor="#cccccc">
							<td colspan=4>&nbsp;</td>
						</tr>
                    </table>
                    <table class="adminlist" cellpadding=20>
                        <tr>
                            <th colspan=2>Business Information</th>
                        </tr>
                        <tr>
                            <td align="left" width="20%">Name</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" id="businessname" name="data[business][name]" value="<?php echo $profile['Business']['name']; ?>" title="Please enter business name <br/>" class="{required:true}" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">Keywords</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" name="data[business][keyword]" value="<?php echo $profile['Business']['keyword']; ?>" title="" class="" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">Street</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" id="street" name="data[business][street]" value="<?php echo $profile['Business']['street']; ?>" title="Please enter street<br/>" class="{required:true}" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">City</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" id="city" name="data[business][city]" value="<?php echo $profile['Business']['city']; ?>" title="Please enter city" class="{required:true}" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">State</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <?php echo $form->select("state", $states, $profile['Business']['state'], array("id" => "state", "style" => "width: 210px;", 'title' => 'Please enter state where you state<br/>', 'class' => '{required:true}')) ?>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">Zip Code</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" id="zipcode" name="data[business][zipcode]" value="<?php echo $profile['Business']['zip_code']; ?>" title="Please enter zip code" class="{required:true}" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">Contact Person</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" id="contact_person" name="data[business][contact_person]" value="<?php echo $profile['Business']['contact_person']; ?>" title="" class="" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">Contact No.</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" id="contact_no" name="data[business][contact_no]" value="<?php echo $profile['Business']['contact_no']; ?>" title="" class="" style="width: 400px;">
                                &nbsp;e.g.&nbsp;<i>(999) 999-9999</i>
                            </td>
                        </tr>
                        <tr bgcolor="#efefef">
                            <td colspan=2>&nbsp;</td>
                        </tr>
                        <?php
                         switch ($plan) {
                             case "Enhanced Listing":
                         ?>
                        <tr>
                            <td align="left" valign="top">Description</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <textarea name="data[business][description]" rows="10" cols="55"><?php echo $profile['Business']['description'] ?></textarea>
                            </td>
                        </tr>
                        <tr bgcolor="#efefef">
                            <td colspan=2>&nbsp;</td>
                        </tr>
                        <?php
                             break;

                             case "Premium Listing":
                         ?>
                        <tr>
                            <td align="left" valign="top">Description</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <textarea name="data[business][description]" rows="10" cols="55"><?php echo $profile['Business']['description'] ?></textarea>
                            </td>
                        </tr>
                        <tr bgcolor="#efefef">
                            <td colspan=2>&nbsp;</td>
                        </tr>
                        <tr>
                            <td align="left">Website</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                <input type="text" name="data[business][website]" value="<?php echo $profile['Business']['website']; ?>" title="" class="" style="width: 400px;">
                            </td>
                        </tr>
                        <tr>
                            <td align="left">Graphic to Upload</td>
                            <td align="left" style="border: 1px dotted #ccc; background-color: #efefef;">
                                Current logo:&nbsp;<b><span><?=$profile['Businesses']['logo']?></span></b><br>&nbsp;
                                <input type="file" name="data[register][Image]">
                            </td>
                        </tr>
                        <tr bgcolor="#efefef">
                            <td colspan=2>&nbsp;</td>
                        </tr>
                        <?php
                             break;
                         }
                         ?>
                         <tr>
                            <td>&nbsp;</td>
                            <td align="left"><input type="button" value="Update Profile" style="width: 150px;" class="button" onclick="javascript: checkfields();"></td>
                         </tr>
                    </table>
                    <input type="hidden" name="data[marker][id]" value="<?php echo $profile['Business']['id']; ?>">
                    </form>
                </td>
                <td width="40%" valign="top">
                    <table class="adminlist">
                        <tr>
                            <th>Products/Services</th>
                        </tr>
                        <tr>
                            <td>
                                <?php if ($plan == 'Enhanced Listing' || $plan == 'Premium Listing') { ?>
                                <table class="adminlist" width="100%">
                                    <tr>
                                        <td width="5%" class="subheader">#</td>
                                        <td align="left" width="50%" class="subheader">Name</td>
                                        <td width="10%" class="subheader" align="center">Active</td>
                                        <td width="%" class="subheader">&nbsp;</td>
                                    </tr>
                                <?php
                                 if ($bdetails) {
                                    foreach ($bdetails as $idx => $d) {
                                        $color = ($idx/2 == round($idx/2)) ? "row0" : "row1";
                                 ?>
                                    <tr class="<?=$color?>">
                                        <td><?=$idx+1?></td>
                                        <td align="left"><?=$d['business_details']['offers']?></td>
                                        <td align="center"><?=($d['business_details']['active']==1) ? "Yes" : "No"?></td>
                                        <td align="center">
                                            <a href="<?=$html->url('/admin/bprofile/get/'.$d['business_details']['id'])?>"><?=$html->image('pane/menu/icon-16-checkin.png', array('alt' => 'update', 'border' => 0))?></a>
                                            <a href="<?=$html->url('/admin/bprofile/remove/'.$d['business_details']['id'])?>"><?=$html->image('pane/menu/icon-16-logout.png', array('alt' => 'remove', 'border' => 0))?></a>
                                        </td>
                                    </tr>
                                <?php
                                    }
                                 }
                                 ?>
                                    <tr bgcolor="#CCCCCC">
                                        <td colspan=4>&nbsp;</td>
                                    </tr>
                                </table>
                                <form name="detailsForm" action="<?=$html->url('/admin/bdetails')?>" method="post">
                                <table class="adminlist">
                                    <tr>
                                        <th>:: Details</th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="left"><label>Name:</label>&nbsp;
                                                <input type="text" name="data[bdetails][offer]" style="width: 400px;" value="<?php echo $details[0]['BusinessDetails']['offers']; ?>">
                                            </p>
                                            <p align="left">
                                                <label>Description:</label>&nbsp;<br>
                                                <textarea rows="5" cols="60" name="data[bdetails][description]"><?php echo $details[0]['BusinessDetail']['description']?></textarea>
                                                <br>
                                                <?php
                                                 if (isset($details)) {
                                                     $checked = $details[0]['BusinessDetail']['active'];
                                                 } else {
                                                     $checked = null;
                                                 }
                                                 ?>
                                                <input type="checkbox" name="data[bdetails][active]" value="on" checked="<?php echo $checked; ?>">
                                            </p>
                                            <input type="hidden" name="data[bdetails][business_id]" value="<?php echo $profile[0]['Business']['id']; ?>">
                                            <input type="hidden" name="data[window][id]" value="<?php echo $profile[0]['BusinessDetail']['id']; ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="left">
                                            <input type="button" value="Save" class="button" style="width: 100px;" onclick="javascript: document.detailsForm.submit();">
                                            <?=$html->link('Reset', '/admin/bprofile')?>
                                        </td>
                                    </tr>
                               </table>
                               </form>
                               <?php } else { ?>
                                   <p style="font-size: 12px;"><b>This section is not available in your plan.</b></p>
                               <?php } ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</div>
<script language="javascript">
function submitthis(frm)
{
    var action = document.getElementById('flag').value
    switch (action) {
        case "update":
            if (confirm('Are you sure you want to update this data?')) {
                frm.submit();
            }
        break

        case "remove":
            if (confirm('Are you sure you want to remove this data?')) {
                frm.submit();
            }
        break
    }
}
function checkformat()
{
    var pattern = /(\+)?([-\._\(\) ]?[\d]{3,20}[-\._\(\) ]?){2,10}/
    result = document.getElementById('contact_no').value.match(pattern)
    if (!result) {
        alert('Contact number should be (999) 999-9999')
        document.getElementById('contact_no').focus()
    }
}
function checkfields()
{
    var bname = document.getElementById('businessname').value
    var street = document.getElementById('street').value
    var city = document.getElementById('city').value
    var state = document.getElementById('state').value
    var zipcode = document.getElementById('zipcode').value
    var contact_no = document.getElementById('contact_no').value

    var pattern_email = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
    var pattern_phone_no = /(\(\d{3})\)\s\d{3}-\d{4}/
    var pattern_zipcode = /^\d{5}(-\d{4})?$/

    var x = 0

    if (!bname || !street || !city || !state) {
        alert('Please fill up the registration form')
    } else {
        if (contact_no) {
            rc = contact_no.match(pattern_phone_no)
            if (!rc) {
                alert('Invalid phone number format')
                x++
            }
        }
        if (zipcode) {
            rz = zipcode.match(pattern_zipcode)
            if (!rz) {
                alert('Invalid zip code format')
                x++
            }
        }

        if (x == 0) {
            document.adminForm.submit();
        }
    }
}
</script>
